package com.xhs.controller;

import com.xhs.service.Thread7Service;
import com.xhs.service.Thread8Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @desc:
 * @projectName: tools-parent
 * @author: xhs
 * @date: 2022/12/5 21:15
 * @version: JDK 1.8
 */
@Slf4j
@RestController
@RequestMapping("/thread")
public class ThreadController {

    @Resource
    private Thread7Service thread7Service;
    @Resource
    private Thread8Service thread8Service;

    /**
     * 使用Spring的@Async异步注解创建多线程
     *
     * @return String
     */
    @GetMapping("/getName")
    public String getName() {
        log.info(">>>>>>>>>>>>>>使用Spring的@Async异步注解创建多线程,我是主线程:{}<<<<<<<<<<<<<<<<<<<<", Thread.currentThread().getName());
        thread7Service.asyncLog();
        log.info(">>>>>>>>>>>>>>使用Spring的@Async异步注解创建多线程,我是主线程:{}<<<<<<<<<<<<<<<<<<<<", Thread.currentThread().getName());
        return "success";
    }


    /**
     * 使用Spring的@Async异步注解+线程池创建多线程
     *
     * @return String
     */
    @GetMapping("/getUserInfo")
    public String getUserInfo() {
        log.info(">>>>>>>>>>>>>>使用Spring的@Async异步注解+线程池创建多线程,我是主线程:{}<<<<<<<<<<<<<<<<<<<<", Thread.currentThread().getName());
        thread8Service.asyncThread();
        log.info(">>>>>>>>>>>>>>使用Spring的@Async异步注解+线程池创建多线程,我是主线程:{}<<<<<<<<<<<<<<<<<<<<", Thread.currentThread().getName());
        return "success";
    }
}
